function postAjax(url,data,callback){
    $.ajax({
        url:url,
        type:'POST', //GET
        async:true,    //或false,是否异步
        data:data,
        dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
        success:function(data,textStatus,jqXHR){
            if(data.flag){
                callback();
            }else{
                alert(data.msg);
            }
            console.log(data);
            console.log(textStatus);
            console.log(jqXHR);
        },
        error:function(xhr,textStatus){
            console.log(xhr);
            console.log(textStatus);
        },
    });
}
function login(){
    var name = $('#loginname').val();
    var password = $('#password').val();
    if($.trim(name) && $.trim(password)){
        var url = "/user/login";
        var data = {'name':name,'password':password};
        var callback = function(){
            window.location.href = '/home/index';
        }
        postAjax(url,data,callback);
    }else{
        alert('no username or password');
    }
    return;
}